export const state = () => ({
  isLogin: false,
  nav: [],
  appLoading: false,
  baseConfig: {}
});

export const mutations = {
  setAppLoading(state, payload) {
    state.appLoading = payload;
  },
  setNav(state, payload) {
    state.nav = payload;
  },
  setBaseConfig(state, payload) {
    state.baseConfig = payload;
  }
};

export const actions = {
  async getNav({ commit }, payload) {
    const data = await this.$cateService.list({ fid: 0, module: "news" });
    commit("setNav", data.data);
  },
  async getBaseConfig({ commit }, payload) {
    const config = {};
    const arr = [
      "phone",
      "icp",
      "email",
      "address",
      "domain",
      "keywords",
      "description"
    ];
    for (let i = 0; i < arr.length; i++) {
      const key = `web_${arr[i]}`.toUpperCase();
      config[key] = await this.$configService.detail({ key });
    }
    commit("setBaseConfig", config);
  },
  async nuxtServerInit({ dispatch }) {
    await dispatch("getNav");
    await dispatch("getBaseConfig");
  }
};
